import { createRouter, createWebHistory } from 'vue-router'

// 导入组件
import HomeView from '../views/HomeView.vue'

// 定义路由
const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    meta: { title: '首页' }
  },
  {
    path: '/basic-map',
    name: 'basicMap',
    component: () => import('../components/demo1_vue3ol0.vue'),
    meta: { title: '基础地图' }
  },
  {
    path: '/vector-draw',
    name: 'vectorDraw',
    component: () => import('../components/矢量化及切换底图.vue'),
    meta: { title: '矢量绘制' }
  },
  {
    path: '/GeoServerService',
    name: 'GeoServerService',
    component: () => import('../components/GeoServerService.vue'),
    meta: { title: 'GeoServer' }
  },
  {
    path: '/turf-analysis',
    name: 'turfAnalysis',
    component: () => import('../components/TurfSpatialAnalysis.vue'),
    meta: { title: 'Turf空间分析' }
  },
  {
    path: '/wps',
    name: 'wps',
    component: () => import('../components/wps.vue'),
    meta: { title: 'WPS缓冲区分析' }
  },
  {
    path: '/distance-area',
    name: 'distanceArea',
    component: () => import('../components/distanceArea.vue'),
    meta: { title: '测距测面积' }
  },
]

// 创建路由实例
const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由前置守卫 - 设置页面标题
router.beforeEach((to, from, next) => {
  // 设置页面标题
  document.title = to.meta.title ? `${to.meta.title} - OpenLayers Demo` : 'OpenLayers Demo'
  next()
})

export default router